package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Discountmode;
import com.restaurant.service.DiscountmodeService;

public class DiscountmodeServiceImpl implements DiscountmodeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountmode addOrModify( Discountmode objDiscountmode ) {
       return ( Discountmode ) hibernateTemplate.merge( objDiscountmode );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountmode deleteRecord( Discountmode objDiscountmode ) {
       hibernateTemplate.delete( objDiscountmode );
       return objDiscountmode;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountmode modifyRecord( Discountmode objDiscountmode ) {
       return ( Discountmode ) hibernateTemplate.merge( objDiscountmode );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Discountmode> loadAll() {
       return (List<Discountmode>)hibernateTemplate.findByNamedQuery( "Discountmode.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountmode loadByPrimaryKey( Long primaryKey ) {
       return (Discountmode) hibernateTemplate.get( Discountmode.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Discountmode deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Discountmode> loadByHql(String query) {
       return ( List<Discountmode> ) hibernateTemplate.find( query );
   }
}